LD		= ld
LDFLAGS		= -r -m elf_i386
CC		= g++
CFLAGS		= -I include/ -c -fno-builtin -m32 -fno-exceptions -fno-rtti -Wall  
ASM		= nasm
SFLAGS		= -f elf
TARGET		= .MAIN.o
OBJS		= head.o main.o exception.o irq.o pic.o print.o string.o syscall.o system.o var.o iis.o scheduler.o allocator.o

.PHONY: clean sd

all:	clean $(TARGET)
	rm -f $(OBJS)

sd:
	$(CC) -M entry/*.cpp -I include/
	$(CC) -M global/*.cpp -I include/
	$(CC) -M river/*.cpp -I include/
	$(CC) -M sys/*.cpp -I include/

clean :
	rm -f $(OBJS)

$(TARGET): $(OBJS)
	$(LD) $(LDFLAGS) -o $@ $(OBJS)

head.o: entry/head.s
	$(ASM) $(SFLAGS) -o $@ $<

main.o: entry/main.cpp include/sys/style.hpp include/river/iis.hpp \
 include/river/scheduler.hpp include/global/var.hpp include/global/system.hpp
	$(CC) $(CFLAGS) -o $@ $<

exception.o: global/exception.cpp include/sys/style.hpp \
 include/sys/asm.hpp include/global/exception.hpp
	$(CC) $(CFLAGS) -o $@ $<
irq.o: global/irq.cpp include/sys/style.hpp include/sys/asm.hpp \
 include/global/irq.hpp
	$(CC) $(CFLAGS) -o $@ $<
pic.o: global/pic.cpp include/sys/style.hpp include/sys/asm.hpp \
 include/global/pic.hpp
	$(CC) $(CFLAGS) -o $@ $<
print.o: global/print.cpp include/sys/style.hpp include/sys/asm.hpp \
 include/global/print.hpp
	$(CC) $(CFLAGS) -o $@ $<
string.o: global/string.cpp include/global/string.hpp
	$(CC) $(CFLAGS) -o $@ $<

syscall.o: global/syscall.cpp include/sys/style.hpp include/sys/asm.hpp \
 include/global/syscall.hpp
	$(CC) $(CFLAGS) -o $@ $<

system.o: global/system.cpp include/sys/style.hpp include/sys/asm.hpp \
 include/global/system.hpp
	$(CC) $(CFLAGS) -o $@ $<
var.o: global/var.cpp include/sys/style.hpp include/sys/asm.hpp \
 include/river/iis.hpp include/river/scheduler.hpp include/global/var.hpp
	$(CC) $(CFLAGS) -o $@ $<
iis.o: river/iis.cpp include/sys/style.hpp include/sys/asm.hpp \
 include/river/iis.hpp include/global/var.hpp include/global/pic.hpp \
 include/global/exception.hpp include/global/previlege.hpp \
 include/global/irq.hpp include/global/syscall.hpp
	$(CC) $(CFLAGS) -o $@ $<
scheduler.o: river/scheduler.cpp include/sys/style.hpp \
 include/river/scheduler.hpp
	$(CC) $(CFLAGS) -o $@ $<
allocator.o: sys/allocator.cpp include/sys/allocator.hpp \
 include/global/print.hpp
	$(CC) $(CFLAGS) -o $@ $<
